﻿// -----------------------------------------------------------------------
// <copyright file="Team.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace SoftServe.HrManager
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    using SoftServe.HrManager.Models;
    using SoftServe.HrManager.Abstractions;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Team : CollectionBase, ICollection<IDeveloper>
    {
        public string Name { get; set; }

        #region ICollection<IDeveloper>

        public void Add(IDeveloper item)
        {
            if (item == null)
                throw new ArgumentNullException();

            if (List.IndexOf(item) > -1)
                throw new InvalidOperationException("Team member already exists");

            List.Add(item);
        }

        public bool Contains(IDeveloper item)
        {
            return List.IndexOf(item) > -1;
        }

        public void CopyTo(IDeveloper[] array, int arrayIndex)
        {
            List.CopyTo(array, arrayIndex);
        }

        public bool IsReadOnly
        {
            get { return List.IsReadOnly; }
        }

        public bool Remove(IDeveloper item)
        {
            int index = List.IndexOf(item);

            if (index > -1)
                List.Remove(item);

            return index > -1;
        }

        #endregion

        #region IEnumerable<IDeveloper> implementation

        IEnumerator<IDeveloper> IEnumerable<IDeveloper>.GetEnumerator()
        {
            foreach (IDeveloper member in List)
                yield return member;
        }

        #endregion

        public void AddRange(List<IDeveloper> devs)
        {
            foreach (var item in devs)
            {
                List.Add(item);
            }
        }

        public Team()
        {
                
        }

        public Team(List<IDeveloper> frontEnd, List<IDeveloper> backEnd)
        {
            this.AddRange(frontEnd);
            this.AddRange(backEnd);
        }
        
        public bool IsContainsSkill(eSkillName skill)
        {
            foreach (IDeveloper member in List)
            {

                if (mSkillChecker.AssertSkill(member, skill))
                    return true;

            }

            return false;
        }

        private readonly SkillComparerBase mSkillChecker = new DevSkillChecker();
    }
}
